<?php

global $_W, $_GPC;
$_GPC['do'] = 'navigate';
$_GPC['menu'] = 'card';

if ($_GPC['act'] == 'mutdelete') {
    $ids = $_GPC['ids'];
    foreach ($ids as $id) {
        M('navigate')->delete($id);
    }
    message('删除成功', referer(), 'success');
}
if ($_GPC['act'] == 'edit') {
    $id = intval($_GPC['id']);
    if ($_W['ispost']) {
        $data = array();
        $data['uniacid'] = $_W['uniacid'];
        if (isset($_GPC['name'])) {
            $data['name'] = trim($_GPC['name']);
        }
        if (!empty($_GPC['image'])) {
            $data['image'] = trim($_GPC['image']);
        }
        if (isset($_GPC['link'])) {
            $data['link'] = trim($_GPC['link']);
        }
        if (isset($_GPC['sort'])) {
            $data['sort'] = intval($_GPC['sort']);
        }

        $data['create_time'] = time();
        if (!empty($id)) {
            $data['id'] = $id;
            unset($data['create_time']);
            $question = M('navigate')->update($data);
        } else {
            $question = M('navigate')->update($data);
        }
        message('保存成功', $this->createWebUrl('navigate'), 'success');
    }
    $item = M('navigate')->getInfo($id);
    include $this->template('navigate_edit');
    exit;
}
if ($_GPC['act'] == 'delete') {
    $id = intval($_GPC['id']);
    if (empty($id)) {
        if ($_W['ispost']) {
            $data = array();
            $data['status'] = 1;
            $data['message'] = '参数错误';
            die(json_encode($data));
        } else {
            message('参数错误', referer(), 'error');
        }
    }
    M('navigate')->delete($id);
    if ($_W['ispost']) {
        $data = array();
        $data['status'] = 1;
        $data['message'] = '操作成功';
        die(json_encode($data));
    } else {
        message('删除成功', referer(), 'success');
    }
}
$page = !empty($_GPC['page']) ? intval($_GPC['page']) : 1;
$where = "";
$list = M('navigate')->getList($page, $where);
include $this->template('navigate');